<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    //使用innerHTML创建html页面元素
    var body = document.querySelector('body');
    var ary = ["张三","李四","王五"];
    var ul = [];

    ul.push('<ul>');
      for(var i = 0; i < ary.length; i++){
        ul.push('<li>'+ary[i]+'</li>')
      }
    ul.push('</ul>');

    console.log(ul);
    body.innerHTML = ul.join(' ');
    
    //获取生成好的li
    var lis = document.querySelectorAll('li');
    for(var i = 0; i <lis.length; i++){
      lis[i].onmouseleave = function(){
        this.style.backgroundColor = '';
      }
      lis[i].onmouseenter = function(){
        this.style.backgroundColor = 'red';
      }
    }
  </script>
</body>
</html>